<%@page import="com.ce.framework.util.StringUtil"
%><%@ page language="java" pageEncoding="UTF-8"
%><%@ page import="java.net.*"
%><%@ page import="java.awt.*"%><%@ page import="java.awt.image.*"%><%@ page import="java.io.*"%><%@ page import="javax.imageio.*"%><%@ page import="com.sun.image.codec.jpeg.*"%><%
        int width = 400;
        int height = 300;
        try{
	        width = Integer.parseInt(request.getParameter("width"));   
	        height = Integer.parseInt(request.getParameter("height"));
        }catch(Exception e){
        	return;
        }
        String title = request.getParameter("title");
        if(StringUtil.isBlank(title)){
        	title = "统计图";
        }
        System.out.println(URLEncoder.encode(title+".jpg","UTF-8"));
  
        BufferedImage result = new BufferedImage(width, height,   
                BufferedImage.TYPE_INT_RGB);   
        // 页面是将一个个像素作为参数传递进来的,所以如果图表越大,处理时间越长   
        for (int y = 0; y < height; y++) {   
            int x = 0;   
            String[] row = request.getParameter("r" + y).split(",");   
            for (int c = 0; c < row.length; c++) {   
                String[] pixel = row[c].split(":"); // 十六进制颜色数组   
                int repeat = pixel.length > 1 ? Integer.parseInt(pixel[1]) : 1;   
                for (int l = 0; l < repeat; l++) {   
                    result.setRGB(x, y, Integer.parseInt(pixel[0], 16));   
                    x++;   
                }   
            }   
        }
        response.setContentType("image/jpeg");   
        response.addHeader("Content-Disposition",   
                "attachment; filename=\""+URLEncoder.encode(title+".jpg","UTF-8")+"\"");   
        Graphics2D g = result.createGraphics();   
        // 处理图形平滑度   
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,   
                RenderingHints.VALUE_ANTIALIAS_ON);   
        g.drawImage(result, 0, 0, width, height, null);   
        g.dispose();   
  
        ServletOutputStream f = response.getOutputStream();   
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(f);   
        JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(result);   
        param.setQuality((float) (100 / 100.0), true);// 设置图片质量,100最大,默认70   
        encoder.encode(result, param);   
        ImageIO.write(result, "JPEG", response.getOutputStream());// 输出图片   
        f.close();  
%>